package com.tyk.bookstore.front.order.service.impl;


import com.tyk.bookstore.front.common.core.util.AssertUtil;
import com.tyk.bookstore.front.order.model.dto.Order4CommentDto;
import com.tyk.bookstore.front.order.model.entity.OrderDetailDo;
import com.tyk.bookstore.front.order.model.result.OrderResultEnum;
import com.tyk.bookstore.front.order.repository.OrderDetailRepository;
import com.tyk.bookstore.front.order.repository.OrderRepository;
import com.tyk.bookstore.front.order.service.OrderDetailApiService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author tyk
 * @description 订单明细对内暴露接口
 */
@Service
@RequiredArgsConstructor
public class OrderDetailApiServiceImpl implements OrderDetailApiService {
    private final OrderDetailRepository orderDetailRepository;
    private final OrderRepository orderRepository;

    @Override
    public Order4CommentDto getOrder4CommentDtoById(Long id, Long memberId) {
        Order4CommentDto dto = orderDetailRepository.selectOrder4CommentDtoById(id, memberId);
        AssertUtil.notNull(dto, OrderResultEnum.ORDER_NOT_FOUND);
        return dto;
    }


    @Override
    public void updateCommentId(Long commentId, Long id, Long memberId) {
        orderDetailRepository.update1Set2Eq(
                OrderDetailDo::getCommentId, commentId,
                OrderDetailDo::getId, id,
                OrderDetailDo::getMemberId, memberId,
                OrderDetailDo.class
        );
    }
}
